enum BTN {
    //% block="K1"
    1,
    //% block="K2"
    2,
    //% block="K3"
    3
	//%block="K4"
	4
}
enum MOTOR {
    //% block="A"
    0,
    //% block="B"
    1,
    //% block="C"
    2
	//%block="D"
	3
}
enum DIG
{
	//% block="3"
	3,
	//% block="5"
	5,
	//% block="6"
	6,
	//%block="7"
	7,
	//% block="8"
	8,
	//%block="9"
	9,
	//% block="A0"
	A0,
	//%block="A1"
	A1,
	//% block="A2"
	A2,
	//%block="A3"
	A3,
	
	
}
enum COLORS
{
	//% block="黑"
	1,
	//% block="白"
	0,
}
enum LIGHTS
{
	//% block="左"
	0,
	//% block="右"
	1,
}
enum WULUXUNJI
{
	//% block="1"
	1,
	//% block="2"
	2,
	//% block="3"
	3,
	//% block="4"
	4,
	//% block="5"
	5	
}
enum HX6050
{
	//% block="X角度"
	1,
	//% block="Y角度"
	2,
	//% block="Z角度"
	3
}
enum RNKJ
{
	//% block="专注度"
	1,
	//% block="放松度"
	2,
}


namespace HXSY {
	//% block="电机 [SW]以[SP]速度开始启动" blockType="command"
	//% SW.shadow="dropdown" SW.options="MOTOR" SW.defl="MOTOR.0"
	//%SP.shadow="range"   SP.params.min=-60    SP.params.max=60    SP.defl=0
	export function MOTOR_SEND_START(parameter: any, block: any) {
		let mo = parameter.SW.code
		let ss = parameter.SP.code
		Generator.addInclude('HXSY', '#include <HXSY.h>');
		Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
		Generator.addCode(`HX_block.MOTOR_SEND_START(${mo},${ss});`);
	}
    //% block="电机 [SW] 速度设为[SP]" blockType="command"
    //% SW.shadow="dropdown" SW.options="MOTOR" SW.defl="MOTOR.0"
	//%SP.shadow="range"   SP.params.min=-60    SP.params.max=60    SP.defl=0
    export function MOTOR_SEND(parameter: any, block: any) {
		let mo = parameter.SW.code
		let ss = parameter.SP.code
		Generator.addInclude('HXSY', '#include <HXSY.h>');
		Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
		Generator.addCode(`HX_block.MOTOR_SEND(${mo},${ss});`);
    }
	//% block="电机开始运行" blockType="command"
	export function MOTOR_START(parameter: any, block: any) {

		Generator.addInclude('HXSY', '#include <HXSY.h>');
		Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
		Generator.addCode(`HX_block.MOTOR_START();`);
	}
	
	//% block="停止电机 [SW] " blockType="command"
	//% SW.shadow="dropdown" SW.options="MOTOR" SW.defl="MOTOR.0"
	export function MOTOR_STOP_ONE(parameter: any, block: any) {
			let mo1 = parameter.SW.code
			Generator.addInclude('HXSY', '#include <HXSY.h>');
			Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
			Generator.addCode(`HX_block.MOTOR_STOP_ONE(${mo1});`);
		}
	//% block="停止全部电机" blockType="command"
	export function MOTOR_STOP(parameter: any, block: any) {
	
		Generator.addInclude('HXSY', '#include <HXSY.h>');
		Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
		Generator.addCode(`HX_block.MOTOR_STOP();`);
	}
	
    //% block="端口[DD]的按钮 [BUTTON]被按下?" blockType="boolean"
	//% Flag.shadow="boolean"
	//% BUTTON.shadow="dropdown" BUTTON.options="BTN" BUTTON.defl="BTN.1"
    //% DD.shadow="dropdown" DD.options="DIG" BUTTON.defl="DIG.3"
    export function buttonPressed(parameter: any, block: any) {
           let dn = parameter.DD.code
		   let sbu = parameter.BUTTON.code
		   Generator.addInclude('HXSY', '#include <HXSY.h>');
		   Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
           Generator.addCode([`HX_block.buttonPressed(${dn},${sbu})`,Generator.ORDER_UNARY_POSTFIX]);       
    }

     //% block="等待端口[DD]的按钮 [BUTTON]被松开 " blockType="command"
     //% BUTTON.shadow="dropdown" BUTTON.options="BTN" BUTTON.defl="BTN.1"
     //% DD.shadow="dropdown" DD.options="DIG" BUTTON.defl="DIG.3"
     export function waitbutton(parameter: any, block: any) {
		   let dn = parameter.DD.code
		   let sbu = parameter.BUTTON.code
		   Generator.addInclude('HXSY', '#include <HXSY.h>');
		   Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
		   Generator.addCode(`HX_block.waitbutton(${dn},${sbu});`); 
    }
	
	//% block="数码管[DD]显示 [SEG] " blockType="command"
	//% SEG.shadow="number"   SEG.defl="0000"
	//% DD.shadow="dropdown" DD.options="DIG" DD.defl="DIG.3"
	export function WriteSEG(parameter: any, block: any) {
		  let dn = parameter.DD.code
		  let SE = parameter.SEG.code
		  Generator.addInclude('HXSY', '#include <HXSY.h>');
		  Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
		  Generator.addCode(`HX_block.WriteSEG(${dn},${SE});`); 
	}
	
	//% block="寻迹[DD]的[light]检测到[color]色 " blockType="boolean"
	 //% Flag.shadow="boolean"
	 //% light.shadow="dropdown" light.options="LIGHTS" light.defl="LIGHTS.0"
	 //% color.shadow="dropdown" color.options="COLORS" color.defl="COLORS.1"
	 //% DD.shadow="dropdown" DD.options="DIG" DD.defl="DIG.3"
	 export function LIGHT_B_W(parameter: any, block: any) {
		   let dn = parameter.DD.code
		   let li = parameter.light.code
		   let col = parameter.color.code
		   Generator.addInclude('HXSY', '#include <HXSY.h>');
		   Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
		   Generator.addCode(`HX_block.LIGHT_B_W(${dn},${li},${col})`); 
	}
	
	//% block="五路寻迹[DD]的[light]检测到[color]色 " blockType="boolean"
	 //% Flag.shadow="boolean"
	 //% light.shadow="dropdown" light.options="WULUXUNJI" light.defl="WULUXUNJI.1"
	 //% color.shadow="dropdown" color.options="COLORS" color.defl="COLORS.1"
	 //% DD.shadow="dropdown" DD.options="DIG" DD.defl="DIG.3"
	 export function LIGHT5_B_W(parameter: any, block: any) {
		   let dn = parameter.DD.code
		   let li = parameter.light.code
		   let col = parameter.color.code
		   Generator.addInclude('HXSY', '#include <HXSY.h>');
		   Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
		   Generator.addCode(`HX_block.LIGHT5_B_W(${dn},${li},${col})`); 
	}
	
	  //% block="超声波端口[DD]设置[light]颜色2 [COLOR]" blockType="command"
	  //% COLOR.shadow="colorPalette" 
	  //% DD.shadow="dropdown" DD.options="DIG" DD.defl="DIG.3"
	  //% light.shadow="dropdown" light.options="LIGHTS" light.defl="LIGHTS.0"
	  export function HXsetColor(parameter: any, block: any) {
	         let color=parameter.COLOR.code;
			 let di = parameter.DD.code;
			 let as = parameter.light.code;
			 Generator.addInclude('HXSY', '#include <HXSY.h>');
			 Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
			 Generator.addCode(`HX_block.HXsetColor(${di},${as},${color});`); 
	    }
		
		//% block="超声波端口[DD]读取距离（cm）" blockType="reporter"
		//% DD.shadow="dropdown" DD.options="DIG" DD.defl="DIG.3"
		export function HXGETDISTENCE(parameter: any, block: any) {
					 let di = parameter.DD.code;
					 Generator.addInclude('HXSY', '#include <HXSY.h>');
					 Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
					 Generator.addCode(`HX_block.HXGETDISTENCE(${di})`); 
		  }
		  
		//% block="初始化陀螺仪传感器" blockType="command"
		export function HXMPU1(parameter: any, block: any) {
		  			Generator.addInclude('MPU6050HX1', '#include <MPU6050_HX.h>');
		  			Generator.addInclude('MPU6050HX2', '#include <Wire.h>');
		  			Generator.addSetup('MPU6050HX3', "Wire.begin();");
		  			Generator.addSetup('MPU6050HX4', "mpu6050.begin();");
		  			Generator.addSetup('MPU6050HX6', "mpu6050.calcGyroOffsets(true);");
		  			Generator.addObject(`MPU6050HX5`, `MPU6050`, `mpu6050(Wire);`);
		  }
			
		//% block="获取陀螺仪传感器的[MP6]" blockType="reporter"
		//% MP6.shadow="dropdown" MP6.options="HX6050" MP6.defl="HX6050.X角度"
		export function HXmpu6050_get(parameter: any, block: any) {
				    let di = parameter.MP6.code;   
					Generator.addCode(`mpu6050.HXmpu6050_get(${di})`); 
		  }
		
		//% block="获取一次脑波数据" blockType="command"
		export function HXNBGET(parameter: any, block: any) {
		
			Generator.addInclude('HXSY', '#include <HXSY.h>');
			Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
			Generator.addSetup('HXGETTGAM1', "Serial.begin(57600);");
			Generator.addCode(`HX_block.HXNBGET();`);
		}
		//% block="脑波读取[sw]" blockType="reporter"
		//% sw.shadow="dropdown" sw.options="RNKJ" sw.defl="RNKJ.专注度"
		export function HXGETTGAM(parameter: any, block: any) {
					 let tg = parameter.sw.code;
					 Generator.addInclude('HXSY', '#include <HXSY.h>');
					 Generator.addObject(`HX_block`, `HXSY`, `HX_block;`);
					 Generator.addSetup('HXGETTGAM1', "Serial.begin(57600);");
					 Generator.addCode(`HX_block.HXGETTGAM(${tg})`); 
		  }

}
